package my.test.responsibilitychain.best;

import my.test.responsibilitychain.IWomen;

public abstract class Handler {
    public final static int FATHER_LEVER_REQUEST = 1;
    public final static int HUSBAND_LEVER_REQUEST = 2;
    public final static int SON_LEVER_REQUEST = 3;

    //能处理的级别
    private int level = 0;
    //责任传递，下一个责任人是谁
    private Handler nextHandler;
    //每个类说明一下自己能处理那些需求
    public Handler(int level) {
        this.level = level;
    }

    public final void HandleMessage(IWomen women) {
        if(women.getType() == this.level) {
            this.response(women);
        } else {
            if(this.nextHandler != null) {
                this.nextHandler.HandleMessage(women);
            } else {
                System.out.println("没地方请示了，按不同意处理---\n");
            }
        }
    }

    public void setNext(Handler handler) {
        this.nextHandler = handler;
    }

    //有请示当然要回应
    protected abstract void response(IWomen women);
}
